home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
FM Towns: Free Software Collection 10
/
FM Towns Free Software Collection 10.iso
/
ms_dos
/
tool
/
bin2snd
/
binsnd.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-09-15
|
3KB
|
153 lines
#pragma On(public_var_warnings)
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <snd.h>
#include <conio.h>
typedef struct
{
char name[8];
unsigned int id;
unsigned int length;
unsigned int looppoint;
unsigned int looplength;
unsigned short int freq;
unsigned short int adjust;
unsigned char note;
unsigned char reserve1;
unsigned short int reserve2;
char data[0];
} SNDBUF;
char SndWork[SndWorkSize] ;
int Freq = 20*0x62;
int Len = 5*20*1024;
int Vol = 127;
char Filename[256]="";
int arg( int argc, char *argv[] )
{
int i;
char sw, *para;
if ( argc < 2 )
return 1;
for ( i=1; i<argc; i++ ) {
if ( argv[i][0]=='-' || argv[i][0]=='/' ) {
sw = argv[i][1];
if ( sw!='\0' && argv[i][2]!='\0' ) {
para = argv[i] + 2;
} else {
if ( i<argc ) {
i++;
para = argv[i];
} else {
para = NULL;
}
}
switch ( sw ) {
case 'h': case 'H': case '?':
return 'h';
case 'v': case 'V':
Vol = atoi( para );
if ( Vol<1 || 127<Vol ) {
printf("\n ボリュームが不正です.");
return 'v';
}
break;
case 'f': case 'F':
Freq = atoi( para ) * 0x62;
if ( Freq<0 || 20*0x62<Freq ) {
printf("\n 周波数が不正です.");
return 'f';
}
break;
case 'l': case 'L':
Len = atoi( para );
if ( Len<0 ) {
printf("\n 再生バイト数が不正です.");
return 'l';
}
break;
default:
printf("\n 不正なパラメーターです.");
return 2;
}
} else {
strcpy(Filename,argv[i]);
}
}
if (Filename[0]=='\0') {
printf("\n ファイルを指定してください.");
return 3;
}
return 0;
}
int main( int argc, char *argv[] )
{
FILE *fp;
SNDBUF *buf;
if ( arg(argc,argv)!=0 ) {
printf("\nバイナリファイルをPCMデータとして鳴らすツール by Ushio");
printf("\n Use : run386 binsnd [-f freq] [-l len(byte)] filename\n");
return 1;
}
if ( (fp=fopen(Filename,"rb"))==NULL ) {
printf("\n \"%s\" がオープン出来ません.",Filename);
return 1;
}
if ( (buf=(SNDBUF *)malloc(Len+32))==NULL ) {
printf("\n メモリが足りません.");
fclose(fp);
return 1;
}
if ( fread(buf->data, 1, 1, fp)<1 ) { //fread test
printf("\n \"%s\" を読み込めません(data).",Filename);
free(buf);
fclose(fp);
return 1;
}
fseek(fp, 0, SEEK_SET);
buf->name[0] = '\0';
buf->id = 0;
buf->looppoint = 0;
buf->looplength = 0;
buf->freq = Freq;
buf->adjust = 0;
buf->note = 60;
SND_init(SndWork);
SND_elevol_mute(0x01);
SND_pcm_mode_set(1);
printf("freqency %d\n",(int)buf->freq*0x64);
printf("length %#010x %16u\n",Len,Len);
printf("offset %#010x %16u\n",0,0);
while ( (buf->length = fread(buf->data, 1, Len, fp)) > 0 ) {
SND_pcm_play( 71, buf->note, Vol, (char *)buf );
int s0=48,s1=48;
while((SND_pcm_status(71)!=0)&&((s0&48)==48)&&((s1&48)==48)&&(!kbhit())){
SND_joy_in_2(0,&s0);
SND_joy_in_2(1,&s1);
}
SND_pcm_play_stop(71);
if ( ((s0&48)!=48)||((s1&48)!=48)||kbhit() ) {
printf("\n再生を中断しました.");
break;
}
long fs = ftell( fp );
printf("offset %#010x %16u\n",fs,fs);
}
SND_elevol_init();
SND_end();
free(buf);
fclose(fp);
return 0 ;
}